<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="com.uc.training.smadmin.gds.dao.CommentReplyDao">

    <!--获取后台商家回复-->
    <select id="getAdminReplyContent" parameterClass="Long"  resultClass="String">
        select
          content
        from t_gds_comment_reply
        WHERE  comment_id = #commentId# AND `type` = 1
    </select>
    <!--前端根据商品id获取评论-->
    <select id="getCommentReplyList" parameterClass="com.uc.training.smadmin.gds.vo.CommentReplyVO" resultClass="com.uc.training.smadmin.gds.re.CommentReplyRE">
        select
          id,
          member_id AS memberId,
          comment_id AS commentId,
          CONCAT(LEFT(member_nickname,1), '**' ,RIGHT(member_nickname,1)) AS memberNickname,
          (
                CASE
                WHEN member_id = #memberId# THEN
                        1
                ELSE
                        0
                END
          ) isSelf,
          NOW()  AS  dateTime,
          member_image_url AS memberImageUrl,
          parent_id AS parentId,
          `type`,
          content,
          create_time AS createTime
        from t_gds_comment_reply
        where comment_id = #commentId# AND `type` = 2
        ORDER BY create_time DESC
    </select>
    <!--新赠商品详情回复-->
    <insert id="insertCommentReply" parameterClass="com.uc.training.smadmin.gds.model.CommentReply">
        INSERT INTO t_gds_comment_reply
        (comment_id, member_id, member_nickname, member_image_url, parent_id, `type`, content, create_emp, modify_emp)
        VALUES (#commentId#, #memberId#, #memberNickname#, #memberImageUrl#, #parentId#, #type#, #content#, #createEmp#, #modifyEmp#)
        <selectKey resultClass="long" keyProperty="id">
            SELECT LAST_INSERT_ID() as id;
        </selectKey>
    </insert>

    <!--删除商品详情回复-->
    <delete id="deleteCommentReplyById" parameterClass="com.uc.training.smadmin.gds.vo.CommentReplyVO">
        DELETE FROM t_gds_comment_reply
        WHERE
        <isNotEmpty property="id">
            id = #id#
        </isNotEmpty>
        <isNotEmpty property="memberId" prepend="and">
            member_id = #memberId#
        </isNotEmpty>
    </delete>

    <!--根据评论ID修改后台评论-->
    <update id="editAdminReplyContent" parameterClass="com.uc.training.smadmin.gds.model.CommentReply">
        UPDATE t_gds_comment_reply
        set content = #content#
        where comment_id = #commentId#
    </update>

</sqlMap>